package com.itheima.web;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.Movies;
import com.itheima.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@Controller
@RestController//Controller+ResponsBody
@RequestMapping("/movie")
public class MovieController {
    @Autowired
    private MovieService movieService;

    @RequestMapping("/findByPage")
    public PageInfo<Movies> findByPage(
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
           Integer cid,
            String  keyword) {
        System.out.println("findByPage执行了");
      PageInfo<Movies> pageInfo=  movieService.findByPage(pageNum, pageSize,cid,keyword);
        return pageInfo;

    }

    /*保存电影的方法*/
    @PostMapping("/save")
    public String save(@RequestBody Movies movies) {
        System.out.println("========="+movies);
        //调用sevice层
        movieService.save(movies);
        return "ok";

    }

    /*通过id查询*/
    @GetMapping("/findById")
    public Movies findById(Integer id) {

      Movies movies=  movieService.findById(id);
        return movies;

    }

    /*通过id删除*/
    @DeleteMapping("/deleteById")
    public String deleteById(Integer id) {
        System.out.println("要删除的id"+id);
        movieService.deleteById(id);

        return "ok";

    }

/*批量删除*/
    @DeleteMapping("/deleteBatch")
    public String deleteBatch( Integer[] ids) {

        movieService.deleteBatch(ids);
        return "ok";
    }



}
